Public Class WebCrawler
    Private DefaultFilename As String = My.Computer.FileSystem.CombinePath(My.Computer.FileSystem.SpecialDirectories.AllUsersApplicationData, "RaidData.bin")

    Public Raids() As RaidData
    Public ProgNotify As WowCrawler.DataAccessProgressNotify

    Public Sub New(ByRef AccessProgressNotify As WowCrawler.DataAccessProgressNotify)
        ReDim Raids(0)
        Raids(0) = New RaidData

        If AccessProgressNotify IsNot Nothing Then
            ProgNotify = AccessProgressNotify
        Else
            ProgNotify = New Prog
        End If
    End Sub


    Public Overridable Function Crawl(ByRef RaidInfo As RaidData, Optional ByVal IsFullUpdate As Boolean = True) As Boolean
    End Function


    Public Sub Export(Optional ByVal Filename As String = "")
        ProgNotify.Notify("Exporting")

        If Filename = "" Then
            Filename = DefaultFilename
        End If

        Dim XmlUtil As New XmlUtils.AccessXml
        XmlUtil.ExportByBin(Raids, Filename)
        'XmlUtil.ExportByXml(Raids, Filename & ".xml")

        ProgNotify.Notify("Export - Done")
    End Sub

    Public Sub Import(Optional ByVal Filename As String = "")
        ProgNotify.Notify("Importing")

        If Filename = "" Then
            Filename = DefaultFilename
        End If

        Dim XmlUtil As New XmlUtils.AccessXml
        XmlUtil.ImportFromBin(Raids, Filename)
        'XmlUtil.ImportFromXml(Raids, Filename & ".xml")

        ProgNotify.Notify("Import - Done")
    End Sub

    Private Class Prog
        Inherits WowCrawler.DataAccessProgressNotify

        Public Overrides Sub Notify(ByVal Message As String)
            '
        End Sub
    End Class

    Public Sub GuessCharaBuild(ByRef Raid As RaidData, Optional ByVal IsFullUpdate As Boolean = True)
        Dim b As Integer
        Dim c As Integer

        For b = 0 To Raid.Bosses.Length - 1
            For c = 0 To Raid.Bosses(b).Characters.Length - 1
                GuessCharaBuildForChara(Raid.Bosses(b).Characters(c), IsFullUpdate)
            Next
        Next
        Export()
    End Sub

    Private Function GuessCharaBuildForChara(ByRef Charas As CharaData, Optional ByVal IsFullUpdate As Boolean = True) As String
        'build guess

        If Charas Is Nothing Then Return ""

        If Charas.CharaBuild Is Nothing Or IsFullUpdate Then
            Charas.CharaBuild = ""
        End If

        Select Case Charas.CharaClass
            Case "Priest"
                If Charas.CharaBuild = "" Then
                    Dim d As Long = 0
                    If Charas.DamageOut IsNot Nothing Then
                        For d = 0 To Charas.DamageOut.Length - 1
                            If InStr(Charas.DamageOut(d).SpellName, "Mind Flay") = 1 Then
                                Charas.CharaBuild = "Shadow"
                                Exit For
                            ElseIf InStr(Charas.DamageOut(d).SpellName, "Vampiric Embrace") = 1 Then
                                Charas.CharaBuild = "Shadow"
                                Exit For
                            ElseIf InStr(Charas.DamageOut(d).SpellName, "Vampiric Touch") = 1 Then
                                Charas.CharaBuild = "Shadow"
                                Exit For
                            End If
                        Next
                    End If
                End If
                If Charas.CharaBuild = "" Then
                    Dim h As Long = 0
                    If Charas.Heals IsNot Nothing Then
                        For h = 0 To Charas.Heals.Length - 1
                            If InStr(Charas.Heals(h).SpellName, "Empowered Renew") = 1 Then
                                Charas.CharaBuild = "Holy"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Penance") = 1 Then
                                Charas.CharaBuild = "Disc"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Circle of Healing") = 1 Then
                                Charas.CharaBuild = "Holy"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Spirit of Redemption") = 1 Then
                                Charas.CharaBuild = "Holy"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Lightwell") = 1 Then
                                Charas.CharaBuild = "Holy"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Vampiric Embrace") = 1 Then
                                Charas.CharaBuild = "Shadow"
                                Exit For
                            End If
                        Next
                    End If
                End If
                'If Charas.CharaBuild = "" Then
                '   Charas.CharaBuild = "Disc"
                'End If

            Case "Druid"
                If Charas.CharaBuild = "" Then
                    Dim d As Long = 0
                    If Charas.DamageOut IsNot Nothing Then
                        For d = 0 To Charas.DamageOut.Length - 1
                            If InStr(Charas.DamageOut(d).SpellName, "Typhoon") = 1 Then
                                Charas.CharaBuild = "Balance"
                                Exit For
                            ElseIf InStr(Charas.DamageOut(d).SpellName, "Starfall") = 1 Then
                                Charas.CharaBuild = "Balance"
                                Exit For
                            ElseIf InStr(Charas.DamageOut(d).SpellName, "Mangle") = 1 Then
                                Charas.CharaBuild = "Feral"
                                Exit For
                            End If
                        Next
                    End If
                End If
                If Charas.CharaBuild = "" Then
                    Dim h As Long = 0
                    If Charas.Heals IsNot Nothing Then
                        For h = 0 To Charas.Heals.Length - 1
                            If InStr(Charas.Heals(h).SpellName, "Wild Growth") = 1 Then
                                Charas.CharaBuild = "Rest"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Swiftmend") = 1 Then
                                Charas.CharaBuild = "Rest"
                                Exit For
                            End If
                        Next
                    End If
                End If

            Case "Paladin"
                If Charas.CharaBuild = "" Then
                    Dim h As Long = 0
                    If Charas.Heals IsNot Nothing Then
                        For h = 0 To Charas.Heals.Length - 1
                            If InStr(Charas.Heals(h).SpellName, "Holy Shock") = 1 Then
                                Charas.CharaBuild = "Holy"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Beacon of Light") = 1 Then
                                Charas.CharaBuild = "Holy"
                                Exit For
                            End If
                        Next
                    End If
                End If

            Case "Shaman"
                If Charas.CharaBuild = "" Then
                    Dim d As Long = 0
                    If Charas.DamageOut IsNot Nothing Then
                        For d = 0 To Charas.DamageOut.Length - 1
                            If InStr(Charas.DamageOut(d).SpellName, "Thunderstorm") = 1 Then
                                Charas.CharaBuild = "Elemental"
                                Exit For
                            ElseIf InStr(Charas.DamageOut(d).SpellName, "Feral Spirit") = 1 Then
                                Charas.CharaBuild = "Enhance"
                                Exit For
                            End If
                        Next
                    End If
                End If
                If Charas.CharaBuild = "" Then
                    Dim h As Long = 0
                    If Charas.Heals IsNot Nothing Then
                        For h = 0 To Charas.Heals.Length - 1
                            If InStr(Charas.Heals(h).SpellName, "Riptide") = 1 Then
                                Charas.CharaBuild = "Rest"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Ancestral Awakening") = 1 Then
                                Charas.CharaBuild = "Rest"
                                Exit For
                            ElseIf InStr(Charas.Heals(h).SpellName, "Earth Shield") = 1 Then
                                Charas.CharaBuild = "Rest"
                                Exit For
                            End If
                        Next
                    End If
                End If
        End Select

        Return Charas.CharaBuild
    End Function


End Class
